<?php

/*
 * 详情控制器
 * @author sky
 * create_time 2017-04-23
 */


namespace App\Front\Controllers\Index;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\Constraint;
use App\Admin\Controllers\Controller;
use App\Admin\Models\Logs;
use App\Front\Models\Collection;
use Session;
use DB;

class CollectionController extends Controller {


    /*
     * 我的收藏
     * @author sky
     * create_time 2017-04-23
     */
    public function Collection(Request $request) {
        if($request->session()->get('name')!=""){
        $id = $request->session()->get('name');
        $bookid = Collection::Collection($id);
        $Collectionlist = DB::table('mini_goods')->whereIn('id',$bookid)->get();
        // dd($Collectionlist);
        $data['Collectionlist'] = $Collectionlist;
            return view('front.collection',$data);
        }else{
            return redirect()->route('login');
        }
    }

    // 添加收藏
    public function addCollection(Request $request){
        $userId = $request->session()->get('name');
        $bookId = $request->input('id');
        // $count = 1;
        $addCollection = array(
            'userId' => $userId,
            'bookId' => $request['id']
            // 'count' => 1
        );   
        if(Collection::AddCollection($addCollection)){
            return 'true';
        }else{
            return 'false';
        }
    }

    public function myorder(Request $request) {
        if($request->session()->get('name')!=""){
        $id = $request->session()->get('name');
        $bookid = Collection::Collection($id);
        $Collectionlist = DB::table('mini_goods')->whereIn('id',$bookid)->get();
        // dd($Collectionlist);
        $data['Collectionlist'] = $Collectionlist;
            return view('front.myorder',$data);
        }else{
            return redirect()->route('login');
        }
    }
}